﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MapControl.Bing.SoapClient;

namespace MapControl.Examples
{
    public partial class FrmBasic : Form
    {
        private BingClient bingClient;
        private List<Marker> markers = new List<Marker>();

        public FrmBasic()
        {
            InitializeComponent();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmBasic));
            mapControl1.Center = new GeoFramework.Position(new GeoFramework.Latitude(53), new GeoFramework.Longitude(18));

            Marker m2 = new Marker(new GeoFramework.Position(new GeoFramework.Latitude(54), new GeoFramework.Longitude(19)));
            m2.Map = mapControl1;
            m2.Show();

            Marker m = new Marker(mapControl1.Center);//, ((System.Drawing.Image)(resources.GetObject("home"))));
            m.Click += new MapEventHandler(m_Click);
            m.Map = mapControl1;
            m.Text = "Awesome";
            m.Show();


            bingClient = new BingClient(mapControl1.ApiKey);
        }

        void m_Click(object sender, MapEventArgs e)
        {
            MessageBox.Show("Yeah " + e.Position.ToString());
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                GeoFramework.Position first = mapControl1.Center;
                bool firstSetted = false;
                foreach (var item in bingClient.GetPositions(txtQuery.Text))
                {
                    Marker m = new Marker(item);
                    m.Map = mapControl1;
                    m.Show();
                    markers.Add(m);
                    if (!firstSetted)
                    {
                        first = item;
                        firstSetted = true;
                    }
                }
                mapControl1.Center = first;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
    }
}